<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Repositories\UserRepository;
use App;
use Auth;
use Carbon\Carbon;
use App\User;

class UserController extends Controller
{
    use AuthUserTrait;
    
    public function __construct(UserRepository $users)
    {

        $this->addMiddleWare(['except' => ['index','switchLanguage','linkPortal']]); //['except' => 'index'] to be removed after auto-login is done!
        $this->users = $users;
    }
    
    public function index(Request $request) {
      if (Auth::check()) {
        $user = Auth::user();
        return response()->json($user);
      } else {

        //to be removed after auto-login is done!
        // $user = User::find(1);
        //  $user = ['id'=>1];
        return response()->json([]);
      }
    }

    public function view(User $user) {
      return response()->json($user);
    }


    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request)
    { 
      
      if (Auth::check()) {
          return response()->json([]);
      }
    }
    public function switchLanguage(Request $request) {
      $locale =  $request->input('locale');
      App::setLocale($locale);
      $request->session()->put('locale', $locale);
    }

    public function linkPortal(){
        $response = new \Illuminate\Http\Response;
        return $response->withCookie('wehcat', 'wehcat', 3);
    }
}
